/* 

	In this file we setup our Windows, Columns and Panels,
	and then inititialize MochaUI.
	
	At the bottom of Core.js you can setup lazy loading for your
	own plugins.

*/

/*
  
INITIALIZE WINDOWS

	1. Define windows
	
		var myWindow = function(){ 
			new MUI.Window({
				id: 'mywindow',
				title: 'My Window',
				contentURL: 'pages/lipsum.html',
				width: 340,
				height: 150
			});
		}

	2. Build windows on onDomReady
	
		myWindow();
	
	3. Add link events to build future windows
	
		if ($('myWindowLink')){
			$('myWindowLink').addEvent('click', function(e) {
				new Event(e).stop();
				jsonWindows();
			});
		}

		Note: If your link is in the top menu, it opens only a single window, and you would
		like a check mark next to it when it's window is open, format the link name as follows:

		window.id + LinkCheck, e.g., mywindowLinkCheck

		Otherwise it is suggested you just use mywindowLink

	Associated HTML for link event above:

		<a id="myWindowLink" href="pages/lipsum.html">My Window</a>	


	Notes:
		If you need to add link events to links within windows you are creating, do
		it in the onContentLoaded function of the new window. 
 
-------------------------------------------------------------------- */

initializeWindows = function(){
	// windows
	// securitystrategyview -> strategy detail config window
	MUI.securitystrategyDetailConfigWindow = function(contentURL,title) {
		new MUI.Window({
			id: 'ssDetailConfig',
			title: '安全策略 - 详细设置 - ' + title,			
			contentURL: contentURL,
			height: 455,
			width: 440,
			resizable: false,
			toolbar2: true,
			toolbar2URL: 'monitorperspective/ssdctoolbar.inc',
			onContentLoaded: function(){
				
			}			
		});
	};
	
	// securitystrategyview -> view all strategy detail window
	MUI.securitystrategyMatrixWindow = function() {
		new MUI.Window({
			id: 'ssMatrixDetail',
			title: '安全策略 - 安全策略矩阵 ',			
			contentURL: 'monitorperspective/securitystrategyMatrix.jsp',
			height: 455,
			width: 740,
			resizable: false,
			onContentLoaded: function(){
				
			}			
		});
	};
	
	// securitystrategyview -> strategy detail config window
	MUI.scheduledTaskDetailConfigWindow = function(contentURL,title) {
		new MUI.Window({
			id: 'stDetailConfig',
			title: '定时任务 - 详细设置 - ' + title,			
			contentURL: contentURL,
			height: 455,
			width: 440,
			resizable: false,
			toolbar2: true,
			toolbar2URL: 'monitorperspective/stdctoolbar.inc',
			onContentLoaded: function(){
				
			}			
		});
	};
	
	// accessmonitorview -> advanced search window
	MUI.accessmonitorAdvancedSearchWindow = function() {
		new MUI.Window({
			id: 'amAdcancedSearch',
			title: '高级查询 - 访问监控',			
			contentURL: 'monitorperspective/accessmonitoradvancedsearch.jsp',
			height: 235,
			width: 240,
			resizable: false,
			toolbar2: true,
			toolbar2URL: 'monitorperspective/amastoolbar.inc',
			onContentLoaded: function(){
//				document.searchForm.userName.focus();
			}			
		});
	};
	
	// accessmonitorview -> report window
	MUI.accessmonitorReportWindow = function() {
		new MUI.Window({
			id: 'amReport',
			title: '报表统计 - 访问监控',			
			contentURL: 'monitorperspective/accessmonitorreport.jsp',
			height: 250,
			width: 450,
			resizable: true,
			toolbar: true,
			toolbarURL: 'monitorperspective/amrtoolbar.inc',
			onContentLoaded: function(){
//				document.searchForm.userName.focus();
			}			
		});
	};
	
	
	// View Controll Event Setter
	if ($('sidebarLinkCheck')) {
		$('sidebarLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MUI.Desktop.sidebarToggle();
		});
	}

	if ($('cascadeLink')) {
		$('cascadeLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.arrangeCascade();
		});
	}

	if ($('tileLink')) {
		$('tileLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.arrangeTile();
		});
	}

	if ($('closeLink')) {
		$('closeLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.closeAll();
		});
	}

	if ($('minimizeLink')) {
		$('minimizeLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.minimizeAll();
		});
	}	


	// Deactivate menu header links
	$$('a.returnFalse').each(function(el) {
		el.addEvent('click', function(e) {
			new Event(e).stop();
		});
	});
	
	// Build windows onLoad
	MUI.myChain.callChain();
};

/*
  
INITIALIZE COLUMNS AND PANELS  

	Creating a Column and Panel Layout:
	 
	 - If you are not using panels then these columns are not required.
	 - If you do use panels, the main column is required. The side columns are optional.
	 
	 Columns
	 - Create your columns from left to right.
	 - One column should not have it's width set. This column will have a fluid width.
	 
	 Panels
	 - After creating Columns, create your panels from top to bottom, left to right.
	 - One panel in each column should not have it's height set. This panel will have a fluid height.	 
	 - New Panels are inserted at the bottom of their column. 
 
-------------------------------------------------------------------- */


initializeColumns = function() {
	// 2 Columns in the Page
	// Left is the thin area locating the: SecurityStrategyView
	// Right is the main area locating the: UserMonitorView, AccessMonitorView
	new MUI.Column({
		id: 'sideColumn',
		placement: 'left',
		width: 345,
		resizeLimit: [200, 345]
	});
	
	new MUI.Column({
		id: 'mainColumn',
		placement: 'main',
		resizeLimit: [300, 600]
	});
	
	
	// Add panels to left column
	new MUI.Panel({
		id: 'SecurityStrategyViewPanel',
		title: '安全策略',	
		contentURL: 'monitorperspective/securitystrategyview.jsp',
		column: 'sideColumn',
		headerToolbox: true,
		headerToolboxURL: 'monitorperspective/securitystrategyviewtoolbar.jsp',
		headerToolboxOnload: function(){
			// bind view all strategys window to button
			if ($('securitystrategy_viewMatrix')) {
				$('securitystrategy_viewMatrix').addEvent('click', function(e) {
					e.stop();
					MUI.securitystrategyMatrixWindow();
				});
			}
		}	
	});
	
	// Add panels to left column
	new MUI.Panel({
		id: 'ScheduledTaskViewPanel',
		title: '定时任务',		
		contentURL: 'monitorperspective/scheduledtaskview.jsp',
		column: 'sideColumn',
		height: 500,
		headerToolbox: false,
		headerToolboxURL: '',
		headerToolboxOnload: function(){
		}	
	});
	
	// Add panels to main column	
	new MUI.Panel({
		id: 'UserMonitorViewPanel',
		title: '用户监控',
		contentURL: 'monitorperspective/usermonitorview.jsp',
		column: 'mainColumn',
		headerToolbox: true,
		headerToolboxURL: 'monitorperspective/usermonitorviewtoolbar.jsp',
		headerToolboxOnload: function(){
			
		}		
	});
	
	new MUI.Panel({
		id: 'AccessMonitorView',
		title: '访问监控',
		contentURL: 'monitorperspective/accessmonitorview.jsp',
		column: 'mainColumn',
		height: 320,
		headerToolbox: true,
		headerToolboxURL: 'monitorperspective/accessmonitorviewtoolbar.jsp',
		headerToolboxOnload: function(){
			// bind advanced search window to button
			if ($('accessmonitor_advancedSearch')) {
				$('accessmonitor_advancedSearch').addEvent('click', function(e) {
					e.stop();
					MUI.accessmonitorAdvancedSearchWindow();
				});
			}
			
			// bind report window to button
			if ($('accessmonitor_report')) {
				$('accessmonitor_report').addEvent('click', function(e) {
					e.stop();
					MUI.accessmonitorReportWindow();
				});
			}
		}
	});
	

	MUI.myChain.callChain();
};

// Initialize MochaUI when the DOM is ready
window.addEvent('load', function(){ //using load instead of domready for IE8
	MUI.myChain = new Chain();
	MUI.myChain.chain(
		function(){MUI.Desktop.initialize();},
		function(){MUI.Dock.initialize();},
		function(){initializeColumns();},
		function(){initWidgets();},
		function(){initializeWindows();}

	).callChain();	

});
